function a(a) {
    var e = !0;
    return 11 != a.length && (e = !1), /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/.test(a) || (e = !1), 
    e;
}

var e = require("../../utils/api.js"), t = getApp();

require("../../utils/disapi.js");

Page({
    data: {
        region: [],
        user: "",
        showfee: !1,
        adr: "",
        store: "",
        name: "",
        phone: "",
        send_price: "",
        is_send: -1,
        lat: "",
        lng: "",
        diy_community_name: t.globalData.diy_community_name
    },
    onLoad: function(a) {
        var n = this;
        e.getTeamOpenid({
            openid: t.globalData.openid
        }).then(function(a) {
            n.setData({
                user: a.data.user,
                name: a.data.user.m_name,
                adr: a.data.user.m_head_address,
                store: a.data.user.m_head_shop_name,
                phone: a.data.user.m_phone,
                send_price: a.data.user.m_send_price,
                is_send: a.data.user.m_is_send,
                lat: a.data.user.m_head_lat,
                lng: a.data.user.m_head_lng,
                adrdetail: a.data.user.m_head_house_address
            }), n.setData({
                region: a.data.user.m_last_location.split(",")
            }), 2 == a.data.user.m_is_send && n.setData({
                showfee: !0
            });
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    switch2Change: function(a) {
        var e = this;
        a.detail.value;
        a.detail.value ? e.setData({
            showfee: !0,
            is_send: 2
        }) : e.setData({
            showfee: !1,
            is_send: 1
        });
    },
    getWxaddress: function(a) {
        var t = this;
        wx.chooseLocation({
            success: function(a) {
                console.log(a), t.setData({
                    adr: a.name,
                    lng: a.longitude,
                    lat: a.latitude
                }), e.GetSnMd5({
                    lng: a.longitude,
                    lat: a.latitude
                }).then(function(a) {
                    console.log(a), t.setData({
                        "region[0]": a.data.province.name,
                        "region[1]": a.data.city.name,
                        "region[2]": a.data.area.name
                    });
                });
            },
            fail: function() {
                console.log("获取地址失败");
            }
        });
    },
    Input: function(a) {
        var e = this, t = a.detail.value, n = a.currentTarget.dataset.name;
        "name" == n ? e.setData({
            name: t
        }) : "phone" == n ? e.setData({
            phone: t
        }) : "wx" == n ? e.setData({
            wx: t
        }) : "store" == n ? e.setData({
            store: t
        }) : "adr" == n ? e.setData({
            adr: t
        }) : "send_price" == n ? e.setData({
            send_price: t
        }) : "adrdetail" == n && e.setData({
            adrdetail: t
        });
    },
    bindRegionChange: function(a) {
        this.setData({
            region: a.detail.value
        });
    },
    btn: function(t) {
        var n = this, o = n.data.name, i = n.data.phone, s = n.data.store, d = n.data.adr, r = n.data.adrdetail, u = n.data.is_send, l = n.data.send_price, c = n.data.region[0] + n.data.region[1] + n.data.region[2];
        if ("" == c || void 0 == c) return wx.showToast({
            title: "请选择地区",
            icon: "none",
            duration: 2e3
        }), !1;
        if ("" == s || void 0 == s) return wx.showToast({
            title: "请填写" + n.data.diy_community_name + "店名",
            icon: "none",
            duration: 2e3
        }), !1;
        if ("" == d || void 0 == d) return wx.showToast({
            title: "请先定位",
            icon: "none",
            duration: 2e3
        }), !1;
        if ("" == r || void 0 == r) return wx.showToast({
            title: "请填写详细地址",
            icon: "none",
            duration: 2e3
        }), !1;
        if (!a(i)) return wx.showToast({
            title: "请填写正确的手机号",
            icon: "none",
            duration: 2e3
        }), !1;
        if ("" == o || void 0 == o) return wx.showToast({
            title: "请填写姓名",
            icon: "none",
            duration: 2e3
        }), !1;
        var m = {
            openid: wx.getStorageSync("openid"),
            name: o,
            phone: i,
            shop_name: s,
            account: n.data.wx,
            address: d,
            adrdetail: r,
            lng: n.data.lng,
            lat: n.data.lat,
            formId: t.detail.formId,
            is_send: u,
            send_price: l,
            region: n.data.region[0] + "," + n.data.region[1] + "," + n.data.region[2]
        };
        console.log(m), e.SetHeadInfo(m).then(function(a) {
            wx.showToast({
                title: a.message,
                icon: "none",
                duration: 2e3
            }), 0 == a.errno && (wx.showToast({
                title: a.message,
                icon: "success",
                duration: 2e3
            }), setTimeout(function(a) {
                wx.navigateBack({
                    detal: 1
                });
            }, 2e3));
        });
    },
    sites: function(a) {
        var e = this;
        console.log(a);
        var t = a.currentTarget.dataset.data_index, n = e.data.footer;
        "url" == n.params.data[t].type ? wx.reLaunch({
            url: n.params.data[t].url
        }) : "tel" == n.params.data[t].type ? wx.makePhoneCall({
            phoneNumber: n.params.data[t].url
        }) : "out_link" == n.params.data[t].type ? wx.navigateTo({
            url: "/pages/template/out_h5?url=" + n.params.data[t].url
        }) : "app" == n.params.data[t].type && wx.navigateToMiniProgram({
            appId: n.params.data[t].url_name,
            path: n.params.data[t].url,
            envVersion: "develop",
            success: function(a) {}
        });
    }
});